
import 'package:fluttertoast/fluttertoast.dart';
import 'package:healthy_station_flutter/utils/log_utils.dart';
import 'package:package_info/package_info.dart';

import '../provider/provider_login.dart';
import 'constants.dart';

///
/// @Description 
/// @Author WuJianFeng
/// @Date 2024/3/5 10:09
/// 

class AppUtils {

  static Future<String> getVersion() async{
    PackageInfo packageInfo = await PackageInfo.fromPlatform();
    try{
      LogUtils.d("__getVersion-1${packageInfo.version}");

    }catch(e){
      LogUtils.d("__getVersion-e$e");

    }
    return packageInfo.version;
  }

  static String calculateAge(String born) {
    return (DateTime.now().year - int.parse(born)).toString();
  }

  static int getBrxz(int cardType) {
    switch(cardType){

      case cardTypeSocialCard: {
        return 2;
      }

      case cardTypeMedicalInsurance: {
        return 3;
      }

      default: {
        return 1;
      }
    }
  }

  static String getUserSex(String userSex) {
    switch(userSex){

      case "1": {
        return "男";
      }

      case "2": {
        return "女";
      }

      default: {
        return userSex;
      }
    }
  }

  static String getLoginModel(int cardType) {
    switch(cardType){

      case cardTypeSocialCard: {
        return loginModelSocialCard;
      }

      case cardTypeMedicalInsurance: {
        return loginModelMedicalInsurance;
      }

      case cardTypeAccountPassword: {
        return loginModelAccount;
      }

      default: {
        return loginModelIdentity;
      }
    }
  }

  static bool checkLogin(){
    if(LoginProvider().loginType != loginTypeSuccess){
      Fluttertoast.showToast(msg: "请先登录");
      return false;
    }
    return true;
  }

  static String getTime(){
    DateTime now = DateTime.now();
    return "${now.year}/${now.month}/${now.day} ${getWeek(now.weekday)} ${now.hour}:${now.minute.toString().length == 2? now.minute:'0${now.minute}'}";
  }

  static String getWeek(int day){
    switch (day) {
      case 1: {
        return '星期一';
      }
      case 2:{
        return '星期二';
      }
      case 3:{
        return '星期三';
      }
      case 4:{
        return '星期四';
      }
      case 5:{
        return '星期五';
      }
      case 6:{
        return '星期六';
      }
      case 7:{
        return '星期日';
      }
      default:{
        return '';
      }
    }
  }
}
 
 